﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Ryder_US_Website.BUS;
using Ryder_US_Website.Utils;

namespace Ryder_US_Website.Presentation.Admin
{
    public partial class Service_Update : System.Web.UI.Page
    {
        //public string id;
        private RUS_Service srv = new RUS_Service();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["RUS_User"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            string id = Request.QueryString["id"];
            int temp = Int16.Parse(id);
            srv = ServiceBUS.GetServiceByID(temp);
            if (!IsPostBack)
            {
                txtTenDichVu.Text = srv.Service_name;
                txtMoTa.Text = srv.Service_description;
                rbConHoatDong.Checked = (srv.Service_trash == 0);
                rbHetHoatDong.Checked = !rbConHoatDong.Checked;
            }
        }

        protected void btnHuy_Click(object sender, EventArgs e)
        {
            Response.Redirect("Service_List.aspx");
        }

        protected void btnCapNhat_Click(object sender, EventArgs e)
        {
            RUS_Service kq = new RUS_Service();// = srv;
            srv.Service_name = txtTenDichVu.Text;
            srv.Service_description = txtMoTa.Text;
            srv.Service_trash = (rbConHoatDong.Checked == true) ? 0 : 1;
            try
            {
                kq = ServiceBUS.Update(srv.Service_name, srv.Service_description, srv.Service_trash, srv.Service_ID);
            }
            catch (Exception ex)
            {
                Response.Write(UtilHelpers.ShowMessage(ex.Message));

            }
            if (srv.Service_ID.Equals(kq.Service_ID))
            {
                 Response.Redirect("Service_List.aspx");
            }
            else
            {
                Response.Write(UtilHelpers.ShowMessage("Cập nhật dịch vụ thất bại."));
            }
        }
    }
}